package com.soikc.kuaidiE.bean;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.soikc.kuaidiE.util.DateFormatUtil;
import com.soikc.kuaidiE.util.ResultSetUtil;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class User implements UserEax {
    private int id;
    private String nickname;
    private String phone;
    private String mail;
    private String password;
    private Date register_time;
    private Date login_time;

    /**
     * 使用结果集创建一个对象
     * @param resultSet
     * @return
     */
    public static User create(ResultSet resultSet) {
        JSONObject jsonObject = ResultSetUtil.toJsonObject(resultSet);
        return jsonObject.toJavaObject(User.class);
    }
    /**
     * 创建一组对象
     * @param resultSet
     * @return
     */
    public static List<User> createList(ResultSet resultSet){
        List<User> list = new ArrayList();
        try {
            while (resultSet.next()){
                list.add(create(resultSet));
            }
        } catch (SQLException err) {
            err.printStackTrace();
        }
        return list;
    }
    public JSONObject toViveObj(){
        JSONObject d = (JSONObject) JSON.toJSON(this);
        d.put("register_time", DateFormatUtil.format(this.register_time));
        d.put("login_time", DateFormatUtil.format(this.login_time));
        d.put("password","********");
        return d;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getRegister_time() {
        return register_time;
    }

    public void setRegister_time(Date register_time) {
        this.register_time = register_time;
    }

    public Date getLogin_time() {
        return login_time;
    }

    public void setLogin_time(Date login_time) {
        this.login_time = login_time;
    }
}
